<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/includeTaglib.jsp"%>
<%@ include file="/WEB-INF/jsp/includeCss.jsp"%>
<%@ include file="/WEB-INF/jsp/includeJs.jsp"%>


<table width="100%" border="0" cellpadding="0" cellspacing="5">
	<tr>
		<td valign="top">
			<table class="dbborder" width="100%" border="0" cellpadding="0"
				cellspacing="0">
				<tr>
					<td valign="bottom" class="blueTableBg">&nbsp;消息公告&nbsp;-&nbsp;推送消息</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

<form target="tempFrame" action="<c:url value="/message/pushMessage.html" ></c:url>" method="post" id="pushMessageForm">
<div class="globalText" style="padding: 15px;border: solid 1px #999999;width: 768px;margin-left: 15px;" >
	<table class="globalText dbborder" width="100%" border="0" cellpadding="5" cellspacing="5" style="margin: 5px;">
		<tr>
			<td>消息标题</td>
			<td>
				<input name="head"  type="text" class="txtbox required" size="20" />
			</td>
		</tr>
		
		<tr>
			<td>消息内容</td>
			<td>
				<textarea rows="10" cols="60" name="body" class="globalText required"></textarea>
			</td>
		</tr>
		<tr>
			<td>重要级别</td>
			<td>
				<select name="priority">
					<option value="NORMAL">NORMAL</option>	
					<option value="URGENT">URGENT</option>		
					<option value="ASSIGN">ASSIGN</option>					
				</select>
			</td>
		</tr>
		<tr>
			<td>接收人员</td>
			<td>
				<span>
					<input value="" class=" required" style="width: 300px;height: auto;" readonly="readonly" id="e12" />
				</span>
				<span>
<!-- 					<input style="vertical-align: top;" onclick="javascript:buildTree(this);" id="addEmpBtn" type="button" class="btnStyle" value="选择人员 "> -->
				</span>
			</td>
		</tr>
		
		
		<tr>
			<td colspan="2" ><input id="sbtn" style="margin-left: 150px;" onclick="javascript:;" type="button" class=" btnStyle" value="提交" /></td>
		</tr>
	</table>
</div>

<input type="hidden" id="receivers" name="receivers" value=""/>

</form>


<script>
	
var addSetting = {
		check: {
			enable: true,
			chkboxType : { "Y" : "", "N" : "" }
		},
		view : {
			dblClickExpand : false
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		callback: {
			onCheck: function(event, treeId, treeNode){
				if(treeNode.loginName){
					if(treeNode.checked){
						
					}else{
						
					}
					var users=$("#e12").val().split(",");
					
				}
			}
		}
	};
	
	
var projectEmployeesJson=${projectEmployees};

var zNodes =new Array();

var userTags=new Array();

var userMap={};

for(var i=0;i<projectEmployeesJson.length;i++){
	zNodes.push({
		id:i+1,
		pId:0,
		name:projectEmployeesJson[i].projectName,
		open:true
	});
	var employees=projectEmployeesJson[i].employees;
	for(var j=0;j<employees.length;j++){
		zNodes.push({
			id:i+""+j,
			pId:i+1,
			name:employees[j].empName,
			loginName:employees[j].loginName,
			open:true
		});
		
		userTags.push(employees[j].empName+"("+projectEmployeesJson[i].projectName+")");
		
		eval('userMap.'+employees[j].loginName+'=employees[j].empName+"("+projectEmployeesJson[i].projectName+")"');
	}
}


function buildTree(obj){
	popUpTree(obj,addSetting,zNodes);
}

if(userTags.length<1){
	$("#e12").css("color","red");
	$("#e12").val("当前没有合适的发送对象");
	$("#e12").attr("disable",true);
}else{
	$("#e12").select2({tags:userTags});
	$("#sbtn").bind("click",doSubmit);
}

function doSubmit(){
	var receivers=new Array();
	if($("#pushMessageForm").valid()){
		var users=$("#e12").val().split(",");
		for(var k=0;k<users.length;k++){
			for(var j in userMap){
				if(users[k]==userMap[j]){
					receivers.push(j);
				}
			}
		}
		if(receivers.length>0){
			var receiversValue="";
			for(var i=0;i<receivers.length;i++){
				receiversValue+=receivers[i]+";";
			}
			$("#receivers").val(receiversValue);
			$("#pushMessageForm").submit();
		}else{
			alert("未选择接收人员!");			
		}
	}
}

var validate=$("#pushMessageForm").validate({
	showErrors: customShowErrors,
	onfocusout:false,
	onkeyup:false,
	onclick:false
});


function submitCallbackSuccess(obj){
	if(obj.sendResults){
		alert(obj.sendResults);
		window.location='<c:url value="/message/pushMessageList.html" />';
	}
}

</script>